home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 1 / Mac Magazin and MacEasy Magazine CD - Issue 01.iso / Sharewarebibliothek / Powermac / C64 / SOURCE / VIC.c < prev    next >
Text File  |  1994-06-06  |  4KB  |  194 lines

  1. /*
  2.     Commodore 64 Emulator v0.4      Earle F. Philhower III 
  3.     Copyright (C) 1993-4            (st916w9r@dunx1.ocs.drexel.edu)
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include "Processor.h"
  21. #include "Memory.h"
  22. #include "Error.h"
  23. #include "Resources.h"
  24. #include "Preferences.h"
  25.  
  26. byte VICText[1024], VICRegister[0x2f];
  27. word VICAddrBase, VICScreenPage, VICCharBase;
  28. byte VICBank, *VICCharDefs;
  29.  
  30. Rect colorWindRect, bwWindRect, colorFullRect, bwFullRect;
  31.  
  32. static int colorInitialized=0;
  33.  
  34. WindowPtr BWVICWind;
  35. CWindowPtr ColorVICWind;
  36.  
  37. void VICAddrAdjust()
  38. {
  39.     VICBank=(RAM[0xdd00]&3)^3;
  40.     VICAddrBase=VICBank*16384;
  41.     VICScreenPage=((RAM[0xd018]&0xf0)>>4)*0x0400+VICAddrBase;
  42.     VICCharBase=((RAM[0xd018]&0x0e)*1024);
  43.     if ((VICBank==1)||(VICBank==3))
  44.         VICCharDefs=RAM+(VICAddrBase+VICCharBase);
  45.     else
  46.         if (VICCharBase==4096) VICCharDefs=charROM;
  47.         else if (VICCharBase==6144) VICCharDefs=charROM+0x0800;
  48.              else VICCharDefs=RAM+(VICAddrBase+VICCharBase);
  49. }
  50.  
  51. byte NotSameVIC()
  52. {
  53.     register byte addr;
  54.     register byte *ramRegister;
  55.     register byte *vicRegister;
  56.     
  57.     ramRegister=&RAM[0xd000];
  58.     vicRegister=&VICRegister[0];
  59.     
  60.     for (addr=0; addr<0x2f; addr++)
  61.     {
  62.         if (addr==0x11)
  63.         {
  64.             if ((*ramRegister++ & 127) != (*vicRegister++ & 127)) return 1;
  65.         }
  66.         else if (addr==0x12);
  67.              else if (*ramRegister++ != *vicRegister++) return 1;
  68.     }
  69.     return 0;
  70. }
  71.  
  72.  
  73.  
  74. void TotalRedrawVIC()
  75. {
  76.     register byte addr;
  77.  
  78.     for (addr=0; addr<0x2f; addr++)
  79.         VICRegister[addr]=RAM[0xd000+addr];
  80.     VICAddrAdjust();
  81.  
  82.  
  83.     if ((globalPref.colorVIC==0)||(colorInitialized==0)) BWTotalRedrawVIC();
  84.     else ColorTotalRedrawVIC();
  85. }
  86.  
  87. void RedrawVIC()
  88. {
  89.     if (NotSameVIC())
  90.     {
  91.         TotalRedrawVIC();
  92.         return;
  93.     }
  94.     VICAddrAdjust();
  95.  
  96.     if ((globalPref.colorVIC==0)||(colorInitialized==0)) BWRedrawVIC();
  97.     else ColorRedrawVIC();
  98. }
  99.  
  100. int VICInitialize()
  101. {
  102.     int err;
  103.     
  104.     if (err=BWVICInitialize()!=kNoError) return err;
  105.     err=ColorVICInitialize();
  106.     if (err==kNoColorSupport)
  107.     {    
  108.         colorInitialized=0;
  109.         err=kNoError;
  110.     }
  111.     else
  112.     {
  113.         colorInitialized=1;
  114.         err=kNoError;
  115.     }
  116.     
  117.     return err;
  118. }
  119.  
  120. void SetVICTitle(Str255 str)
  121. {
  122.     SetWTitle(BWVICWind, str);
  123.     if (colorInitialized) SetWTitle((WindowPtr)ColorVICWind, str);
  124. }
  125.  
  126. void ShowVICWindow()
  127. {
  128.     if (globalPref.doubleSize==1)
  129.     {
  130.         colorWindRect.top = colorFullRect.top * 2;
  131.         colorWindRect.bottom = colorFullRect.bottom * 2;
  132.         colorWindRect.left = colorFullRect.left * 2;
  133.         colorWindRect.right = colorFullRect.right * 2;
  134.         
  135.         bwWindRect.top = bwFullRect.top * 2;
  136.         bwWindRect.bottom = bwFullRect.bottom * 2;
  137.         bwWindRect.left = bwFullRect.left * 2;
  138.         bwWindRect.right = bwFullRect.right * 2;
  139.     }
  140.     else
  141.     {
  142.         colorWindRect=colorFullRect;
  143.         bwWindRect=bwFullRect;
  144.     }
  145.  
  146.     if (colorInitialized)
  147.         SizeWindow((WindowPtr)ColorVICWind, colorWindRect.right-colorWindRect.left,
  148.                                             colorWindRect.bottom-colorWindRect.top, true);
  149.     SizeWindow(BWVICWind, bwWindRect.right-bwWindRect.left, bwWindRect.bottom-bwWindRect.top, true);
  150.  
  151.     
  152.     if ((globalPref.colorVIC==0)||(colorInitialized==0))
  153.     {
  154.         if (colorInitialized) HideColorVIC();
  155.         ShowBWVIC();
  156.     }
  157.     else
  158.     {
  159.         HideBWVIC();
  160.         ShowColorVIC();
  161.     }
  162.     TotalRedrawVIC();
  163. }
  164.  
  165. void DragVICWindow(EventRecord *event)
  166. {
  167.     GrafPtr gp;
  168.     Point x;
  169.     WindowPtr theWind;
  170.     extern Rect dragRect;
  171.     
  172.     FindWindow(event->where, &theWind);
  173.     DragWindow(theWind, event->where, &dragRect);
  174.     
  175.     if (globalPref.byteAlign!=0)
  176.     {
  177.         GetPort(&gp);
  178.         SetPort(theWind);
  179.         x.h=x.v=0;
  180.         LocalToGlobal(&x);
  181.         x.h&=0xfff8;
  182.         MoveWindow(theWind, x.h, x.v, TRUE);
  183.         SetPort(gp);
  184.     }
  185.     
  186.     GetPort(&gp);
  187.     SetPort(theWind);
  188.     x.h=x.v=0;
  189.     LocalToGlobal(&x);
  190.     MoveWindow(BWVICWind, x.h, x.v, TRUE);
  191.     if (colorInitialized) MoveWindow((WindowPtr)ColorVICWind, x.h, x.v, TRUE);
  192.     if (globalPref.colorVIC==0) SelectWindow(BWVICWind);
  193.     SetPort(gp);
  194. }